package com.example.util;

import java.util.Calendar;

public class JudgeDateUtil {

	/**
	 * 验证查询月份是否在财务结算时间允许范围
	 * 
	 * @author tangchengfeng
	 * @Date 2018-04-18 13:49:00
	 * @param dateStr  验证的日期  ：YYYY-MM
	 * @param day	财务结算日 
	 * @return
	 */
	public static Boolean isAllowDate(String dateStr,Integer day){
		if(!dateStr.contains("-"))
		{
			return false;
		}
		String[] yearMonth = dateStr.split("-");
		Integer queryYear = Integer.parseInt(yearMonth[0]);
		Integer queryMongth = Integer.parseInt(yearMonth[1]);	
		Calendar calendar = Calendar.getInstance();
		//不能获取大于当前年份的数据
		if(calendar.get(Calendar.YEAR) < queryYear ){
			return false;
		}
		// 当前日期大于财务结算日期，则不能获取这个月及之后的数据
		else if(calendar.get(Calendar.DATE) > day && calendar.get(Calendar.YEAR) == queryYear && calendar.get(Calendar.MONTH) < queryMongth){
			return false;
		}
		//当前日期小于或等于财务结算日期，则不能获取上个月及之后的数据
		else if((calendar.get(Calendar.DATE) <= day && calendar.get(Calendar.YEAR) == queryYear && calendar.get(Calendar.MONTH) < (queryMongth+1))
				|| (calendar.get(Calendar.DATE) <= day && calendar.get(Calendar.YEAR) == queryYear+1 && calendar.get(Calendar.MONTH) == 0 && queryMongth == 12)){
			return false;
		}
		
		return true;
	}
}
